package com.bocai.yuweiwangluo.activity;


import android.content.Context;
import android.content.SharedPreferences;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.widget.TextView;

import com.bocai.yuweiwangluo.R;
import com.bocai.yuweiwangluo.base.BaseActivity;
import com.bocai.yuweiwangluo.bean.CodeIntroBean;
import com.bocai.yuweiwangluo.net.MyOkHttpClient;
import com.bocai.yuweiwangluo.utils.UrlData;
import com.google.gson.Gson;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;

/**
 * 我的邀请界面
 */
public class MyInvitationActivity extends BaseActivity
{
    @ViewInject(R.id.tv_myinvitation_explain)
    TextView tvExpalain;
    @ViewInject(R.id.tv_myinvitation_invitation)
    TextView tvMyInvitation;
    private static final int RESPONSE_SUCCEED = 1;
    private static final int RESPONSE_FAILED = 2;
    private CodeIntroBean bean;
    @Override
    protected int contentView()
    {
        return R.layout.activity_myinvitation;
    }

    @Override
    protected void setData()
    {
        ViewUtils.inject(this);
        initToolbar("我的邀请");
        MyOkHttpClient myOkHttpClient=new MyOkHttpClient(this,this);
        myOkHttpClient.getCodeIntro(UrlData.BASEURL+UrlData.GETCODEINTRO,handler);
        initEvent();
    }

    @Override
    protected void initEvent()
    {
        super.initEvent();
    }
    Handler handler=new Handler()
    {
        @Override
        public void handleMessage(Message msg)
        {
            super.handleMessage(msg);
            String result = (String) msg.obj;
            Gson gson = new Gson();
            try
            {
                switch (msg.what)
                {
                    case RESPONSE_SUCCEED:
                        Log.e("loginresult", result);
                        bean= gson.fromJson(result, CodeIntroBean.class);
                        SharedPreferences preferences=getSharedPreferences("user", Context.MODE_PRIVATE);
                        String code=preferences.getString("number","无");
                        tvMyInvitation.setText("您的邀请码是"+code);
                        tvExpalain.setText(bean.getRow().getContent());
                        break;
                    case RESPONSE_FAILED:
                        showError(result);
                        break;
                }
            } catch (Exception e)
            {
            }
        }
    };
}
